package com.mucd.chat.config;

import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import java.util.List;
import java.util.Map;

/**
 * @author Apple
 * 配置socket可以访问哪些请求头
 */
public class CustomConfigurator extends ServerEndpointConfig.Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        Map<String, List<String>> headers = request.getHeaders();
        // 将所有的HTTP请求头添加到用户属性中
        for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
            sec.getUserProperties().put(entry.getKey(), entry.getValue());
        }
    }
}